﻿#region Copyright RenGuiYou. All rights reserved.
//=====================================================
// NeatlyFrameWork
// Author:      RenGuiyou
// Feedback: 	mailto:750539605@qq.com
//=====================================================
#endregion

using System.Collections.Generic;
using System;
using Neatly.Module;

public class NeatlyLoom : ModuleSingleton<NeatlyLoom>
{
    private readonly List<Action> m_ActionList = new();
    private readonly List<Action> m_WorkList = new();

    public static void QueueOnMainThread(Action action)
    {
        lock (Instance.m_ActionList)
        {
            Instance.m_ActionList.Add(action);
        }
    }

    public override void Update(float dt)
    {
        lock (m_ActionList)
        {
            m_WorkList.Clear();
            m_WorkList.AddRange(m_ActionList);
            m_ActionList.Clear();
        }
        foreach (var action in m_WorkList)
        {
            action();
        }
    }
}
